<template>
	<view class="cart">
		<view class="title">购物车</view>
		<view class="cartList" v-for="(item,index) in cartList" :key="item.id">
			<!-- 选择按钮 -->
			<view class="goodsCheck">
				<text class="iconfont icon-xuanzhong" 
					:class="{active:item.isSelect}" 
					@click="changeSelect(!item.isSelect,index)"
				></text>
			</view>
			
			<!-- 商品信息 -->
			<view class="goodsItem">
				<view class="goodsImg">
					<image class="" :src="item.listPicUrl" mode=""></image>
				</view>
				<view class="goodsInfo">
					<view class="name">
						{{item.name}}
					</view>
					<view class="price">
						￥ {{item.counterPrice}}
					</view>
				</view>
			</view>
			<view class="countCtrl"> 
				<text class="sub" @click="changeCount(false,index)">-</text>
				<text class="count">{{item.count}}</text>
				<text class="sub" @click="changeCount(true,index)">+</text>
			</view>
		</view>
		<view class="footer">
			<view class="left">
				<text class="iconfont icon-xuanzhong" 
					:class="{active:isAllSelect}" 
					@click="changeAllSelect(!isAllSelect)"
				></text>
				<text>已选 {{totalCount}}</text>
			</view>
			<view class="right">
				<view class="totalCount">合计: ￥ {{totalPrice}}</view>
				<view class="settlement">下单</view>
			</view>
		</view>
	</view>
</template>

<script>
import { mapState, mapGetters, mapMutations } from 'vuex';
	export default {
		data() {
			return {
				
			};
		},
		mounted() {
			// console.log(this.cartList);
		},
		computed: {
			...mapState('cart',['cartList']),
			...mapGetters('cart',['isAllSelect','totalCount','totalPrice'])
		},
		methods: {
			...mapMutations('cart', ['CHANGECOUNT','CHANGESELECT','CHANGEALLSELECT']),
			//数量加减
			changeCount(isAdd,index) {
				this.CHANGECOUNT({isAdd,index})
			},
			//勾选 or 取消勾选
			changeSelect(isSelect,index) {
				this.CHANGESELECT({isSelect,index})
			},
			//全选 or 取消全选
			changeAllSelect(isAll) {
				this.CHANGEALLSELECT(isAll)
			}
		}
	}
</script>

<style lang="less">
	.cart {
		min-height: 100vh;
		background-color: #f5f5f5;
		.title {
			font-size: 36rpx;
			padding: 30rpx 30rpx;
		}
		.cartList {
			display: flex;
			height: 172rpx;
			margin: 20rpx;
			padding: 20rpx;
			background-color: #fff;
			.goodsCheck {
				width: 80rpx;
				line-height: 172rpx;
				.iconfont {
					&.active {
						color: #BB2C08;
					}
				}
			}
			.goodsItem {
				width: 400rpx;
				display: flex;
				.goodsImg {
					width: 250rpx;
					height: 172rpx;
					// background-color: #ddd;
					image {
						width: 172rpx;
						height: 172rpx;
					}
				}
				.goodsInfo {
					.name {
						font-size: 28rpx;
						margin: 20rpx;
						// 设置超出两行显示...
						white-space: pre-wrap;
						overflow: hidden;
						text-overflow: ellipsis;
						display: -webkit-box;
						-webkit-box-orient: vertical;
						-webkit-line-clamp: 2;
					}
					.price {
						color: red;
						margin: 20rpx;
					}
				}
			}
			.countCtrl {
				display: flex;
				margin: 100rpx 0 0 50rpx;
				align-items: center;
				.sub {
					height: 50rpx;
					width: 50rpx;
					line-height: 40rpx;
					background-color: #f5f5f5;
					text-align: center;
					border-radius: 8rpx;
				}
				.count {
					margin: 0 15rpx;
					font-size: 26rpx;
				}
			}
		}
		.footer {
			height: 100rpx;
			width: 100%;
			display: flex;
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			line-height: 100rpx;
			background-color: #fff;
			.left {
				flex: 1.4;
				.iconfont {
					margin: 0 20rpx;
					&.active {
						color: #BB2C08;
					}
				}
			}
			.right {
				display: flex;
				flex: 2;
				.totalCount {
					margin: ;
					flex: 1.5;
				}
				.settlement {
					flex: 1;
					text-align: center;
					color: #fff;
					background-color: #BB2C08;
				}
			}
		}
	}
</style>
